package com.qs.order.message;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @Desc:  mq消息(接受方)
 * @author: jianfeng
 * @Time: 2019/9/23 16:46
 */
@Slf4j
@Component
public class MqReceiver {

    //1、需要手动创建队列  @RabbitListener(queues = "myQueue")
    //2、自动创建  @RabbitListener(queuesToDeclare = @Queue("myQueue"))
    //3、自动创建，Exchange和Queue绑定
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("myQueue"),
            exchange = @Exchange("myExchange")
    ))
    public void process(String message){
        log.info("MqReceiver:{}",message);
    }

    /**
    * @Desc:  数码供应商服务，接受消息，mq分组
    * @author: jianfeng
    * @Time: 2019/9/23 17:22
    * @param message
    * @return void
    */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("computerOrder"),
            key = "computer",
            exchange = @Exchange("myOrder")
    ))
    public void processComputer(String message){
        log.info("computer MqReceiver:{}",message);
    }

    /**
     * @Desc:  水果供应商服务，接受消息，mq分组
     * @author: jianfeng
     * @Time: 2019/9/23 17:22
     * @param message
     * @return void
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("fruitOrder"),
            key = "fruit",
            exchange = @Exchange("myOrder")
    ))
    public void processFruit(String message){
        log.info("fruit MqReceiver:{}",message);
    }

}
